package Practice18;

public class ChiHuo extends Thread {
    private BaoZi baozi;
    public ChiHuo(String name,BaoZi baozi){
        super(name);
        this.baozi=baozi;
    }

    @Override
    public void run() {
        while (true){
            synchronized (baozi){
                if (baozi.flag==false){
                    // 没有包子
                    try{
                        baozi.wait();
                    }catch (InterruptedException e){
                        e.fillInStackTrace();
                    }
                }
                System.out.println("吃货正在吃"+baozi.pier+baozi.xianer+"包子");
                baozi.flag = false;
                baozi.notify();
            }
        }
    }
}
